home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / parted / disk.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-03-16  |  13.0 KB  |  361 lines

  1. /*
  2.     libparted - a library for manipulating disk partitions
  3.     Copyright (C) 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc.
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 3 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. /**
  20.  * \addtogroup PedDisk
  21.  * @{
  22.  */
  23.  
  24. /** \file disk.h */
  25.  
  26. #ifndef PED_DISK_H_INCLUDED
  27. #define PED_DISK_H_INCLUDED
  28.  
  29. /**
  30.  * Partition types
  31.  */
  32. enum _PedPartitionType {
  33.         PED_PARTITION_NORMAL            = 0x00,
  34.         PED_PARTITION_LOGICAL           = 0x01,
  35.         PED_PARTITION_EXTENDED          = 0x02,
  36.         PED_PARTITION_FREESPACE         = 0x04,
  37.         PED_PARTITION_METADATA          = 0x08,
  38.         PED_PARTITION_PROTECTED         = 0x10
  39. };
  40.  
  41. /**
  42.  * Partition flags.
  43.  */
  44. enum _PedPartitionFlag {
  45.         PED_PARTITION_BOOT=1,
  46.         PED_PARTITION_ROOT=2,
  47.         PED_PARTITION_SWAP=3,
  48.         PED_PARTITION_HIDDEN=4,
  49.         PED_PARTITION_RAID=5,
  50.         PED_PARTITION_LVM=6,
  51.         PED_PARTITION_LBA=7,
  52.         PED_PARTITION_HPSERVICE=8,
  53.         PED_PARTITION_PALO=9,
  54.         PED_PARTITION_PREP=10,
  55.         PED_PARTITION_MSFT_RESERVED=11
  56. };
  57. #define PED_PARTITION_FIRST_FLAG        PED_PARTITION_BOOT
  58. #define PED_PARTITION_LAST_FLAG         PED_PARTITION_MSFT_RESERVED
  59.  
  60. enum _PedDiskTypeFeature {
  61.         PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
  62.         PED_DISK_TYPE_PARTITION_NAME=2  /**< supports partition names */
  63. };
  64. #define PED_DISK_TYPE_FIRST_FEATURE    PED_DISK_TYPE_EXTENDED
  65. #define PED_DISK_TYPE_LAST_FEATURE     PED_DISK_TYPE_PARTITION_NAME
  66.  
  67. struct _PedDisk;
  68. struct _PedPartition;
  69. struct _PedDiskOps;
  70. struct _PedDiskType;
  71. struct _PedDiskArchOps;
  72.  
  73. typedef enum _PedPartitionType          PedPartitionType;
  74. typedef enum _PedPartitionFlag          PedPartitionFlag;
  75. typedef enum _PedDiskTypeFeature        PedDiskTypeFeature;
  76. typedef struct _PedDisk                 PedDisk;
  77. typedef struct _PedPartition            PedPartition;
  78. typedef const struct _PedDiskOps        PedDiskOps;
  79. typedef struct _PedDiskType             PedDiskType;
  80. typedef const struct _PedDiskArchOps    PedDiskArchOps;
  81.  
  82. #include <parted/device.h>
  83. #include <parted/filesys.h>
  84. #include <parted/natmath.h>
  85. #include <parted/geom.h>
  86.  
  87. /** @} */
  88.  
  89. /**
  90.  * \addtogroup PedPartition
  91.  * 
  92.  * @{
  93.  */
  94.  
  95. /** \file disk.h */
  96.  
  97. /**
  98.  * PedPartition structure represents a partition.
  99.  */
  100. struct _PedPartition {
  101.         PedPartition*           prev;
  102.         PedPartition*           next;
  103.  
  104.         /**< the partition table of the partition */
  105.         PedDisk*                disk;
  106.         PedGeometry             geom;    /**< geometry of the partition */
  107.  
  108.         /**< the partition number:  In Linux, this is the
  109.              same as the minor number. No assumption
  110.              should be made about "num" and "type" 
  111.              - different disk labels have different rules. */
  112.  
  113.         int                     num;
  114.         PedPartitionType        type;    /**< the type of partition: a bit field of
  115.                           PED_PARTITION_LOGICAL, PED_PARTITION_EXTENDED,
  116.                         PED_PARTITION_METADATA 
  117.                         and PED_PARTITION_FREESPACE.  
  118.                         Both the first two, and the last two are 
  119.                         mutually exclusive.
  120.                             An extended partition is a primary 
  121.                         partition that may contain logical partitions.
  122.                         There is at most one extended partition on 
  123.                         a disk.
  124.                             A logical partition is like a primary 
  125.                         partition, except it's inside an extended 
  126.                         partition. Internally, pseudo partitions are
  127.                         allocated to represent free space, or disk
  128.                         label meta-data.  These have the
  129.                         PED_PARTITION_FREESPACE or
  130.                         PED_PARTITION_METADATA bit set. */
  131.  
  132.         /**< The type of file system on the partition. NULL if unknown. */
  133.         const PedFileSystemType* fs_type;
  134.  
  135.         /**< Only used for an extended partition.  The list of logical
  136.              partitions (and free space and metadata within the extended
  137.              partition). */
  138.         PedPartition*           part_list;
  139.  
  140.         void*                   disk_specific;
  141. };
  142.  
  143. /** @} */
  144.  
  145. /**
  146.  * \addtogroup PedDisk
  147.  * @{
  148.  */
  149.  
  150. /**
  151.  * Represents a disk label (partition table).
  152.  */
  153. struct _PedDisk {
  154.         PedDevice*          dev;         /**< the device where the
  155.                                               partition table lies */
  156.         const PedDiskType*  type;        /**< type of disk label */
  157.         const int*          block_sizes; /**< block sizes supported
  158.                                               by this label */
  159.         PedPartition*       part_list;   /**< list of partitions. Access with
  160.                                               ped_disk_next_partition() */
  161.  
  162.         void*               disk_specific;
  163.  
  164. /* office use only ;-) */
  165.         int                 needs_clobber;      /**< clobber before write? */
  166.         int                 update_mode;        /**< mode without free/metadata
  167.                                                    partitions, for easier
  168.                                                    update */
  169. };
  170.  
  171. struct _PedDiskOps {
  172.         /* disk label operations */
  173.         int (*probe) (const PedDevice *dev);
  174.         int (*clobber) (PedDevice* dev);
  175.         PedDisk* (*alloc) (const PedDevice* dev);
  176.         PedDisk* (*duplicate) (const PedDisk* disk);
  177.         void (*free) (PedDisk* disk);
  178.         int (*read) (PedDisk* disk);
  179.         int (*write) (const PedDisk* disk);
  180.         /** \todo add label guessing op here */
  181.         
  182.         /* partition operations */
  183.         PedPartition* (*partition_new) (
  184.                 const PedDisk* disk,
  185.                 PedPartitionType part_type,
  186.                 const PedFileSystemType* fs_type,
  187.                 PedSector start,
  188.                 PedSector end);
  189.         PedPartition* (*partition_duplicate) (const PedPartition* part);
  190.         void (*partition_destroy) (PedPartition* part);
  191.         int (*partition_set_system) (PedPartition* part,
  192.                                      const PedFileSystemType* fs_type);
  193.         int (*partition_set_flag) (
  194.                 PedPartition* part,
  195.                 PedPartitionFlag flag,
  196.                 int state);
  197.         int (*partition_get_flag) (
  198.                 const PedPartition* part,
  199.                 PedPartitionFlag flag);
  200.         int (*partition_is_flag_available) (
  201.                 const PedPartition* part,
  202.                 PedPartitionFlag flag);
  203.         void (*partition_set_name) (PedPartition* part, const char* name);
  204.         const char* (*partition_get_name) (const PedPartition* part);
  205.         int (*partition_align) (PedPartition* part,
  206.                                 const PedConstraint* constraint);
  207.         int (*partition_enumerate) (PedPartition* part);
  208.  
  209.         /* other */
  210.         int (*alloc_metadata) (PedDisk* disk);
  211.         int (*get_max_primary_partition_count) (const PedDisk* disk);
  212. };
  213.  
  214. struct _PedDiskType {
  215.         PedDiskType*            next;
  216.         const char*             name; /**< the name of the partition table type.
  217.                                            \todo not very intuitive name */
  218.         PedDiskOps* const       ops;
  219.  
  220.         PedDiskTypeFeature      features;   /**< bitmap of supported features */
  221. };
  222.  
  223. /**
  224.  * Architecture-specific operations.  i.e. communication with kernel (or
  225.  * whatever) about changes, etc.
  226.  */
  227. struct _PedDiskArchOps {
  228.         char* (*partition_get_path) (const PedPartition* part);
  229.         int (*partition_is_busy) (const PedPartition* part);
  230.         int (*disk_commit) (PedDisk* disk);
  231. };
  232.  
  233. extern void ped_disk_type_register (PedDiskType* type);
  234. extern void ped_disk_type_unregister (PedDiskType* type);
  235.  
  236. /**
  237.  * Deprecated: use ped_disk_type_register.
  238.  */
  239. __attribute__ ((deprecated))
  240. extern void ped_register_disk_type (PedDiskType* type);
  241.  
  242. /**
  243.  * Deprecated: use ped_disk_type_unregister.
  244.  */
  245. __attribute__ ((deprecated))
  246. extern void ped_unregister_disk_type (PedDiskType* type);
  247.  
  248. extern PedDiskType* ped_disk_type_get_next (PedDiskType* type);
  249. extern PedDiskType* ped_disk_type_get (const char* name);
  250. extern int ped_disk_type_check_feature (const PedDiskType* disk_type,
  251.                                         PedDiskTypeFeature feature);
  252.  
  253. extern PedDiskType* ped_disk_probe (PedDevice* dev);
  254. extern int ped_disk_clobber (PedDevice* dev);
  255. extern int ped_disk_clobber_exclude (PedDevice* dev,
  256.                                      const PedDiskType* exclude);
  257. extern PedDisk* ped_disk_new (PedDevice* dev);
  258. extern PedDisk* ped_disk_new_fresh (PedDevice* dev,
  259.                                     const PedDiskType* disk_type);
  260. extern PedDisk* ped_disk_duplicate (const PedDisk* old_disk);
  261. extern void ped_disk_destroy (PedDisk* disk);
  262. extern int ped_disk_commit (PedDisk* disk);
  263. extern int ped_disk_commit_to_dev (PedDisk* disk);
  264. extern int ped_disk_commit_to_os (PedDisk* disk);
  265. extern int ped_disk_check (const PedDisk* disk);
  266. extern void ped_disk_print (const PedDisk* disk);
  267.  
  268. extern int ped_disk_get_primary_partition_count (const PedDisk* disk);
  269. extern int ped_disk_get_last_partition_num (const PedDisk* disk);
  270. extern int ped_disk_get_max_primary_partition_count (const PedDisk* disk);
  271.  
  272. /** @} */
  273.  
  274. /**
  275.  * \addtogroup PedPartition
  276.  * 
  277.  * @{
  278.  */
  279.  
  280. extern PedPartition* ped_partition_new (const PedDisk* disk,
  281.                                         PedPartitionType type,
  282.                                         const PedFileSystemType* fs_type,
  283.                                         PedSector start,
  284.                                         PedSector end);
  285. extern void ped_partition_destroy (PedPartition* part);
  286. extern int ped_partition_is_active (const PedPartition* part);
  287. extern int ped_partition_set_flag (PedPartition* part, PedPartitionFlag flag,
  288.                                    int state);
  289. extern int ped_partition_get_flag (const PedPartition* part,
  290.                                    PedPartitionFlag flag);
  291. extern int ped_partition_is_flag_available (const PedPartition* part,
  292.                                             PedPartitionFlag flag);
  293. extern int ped_partition_set_system (PedPartition* part,
  294.                                      const PedFileSystemType* fs_type);
  295. extern int ped_partition_set_name (PedPartition* part, const char* name);
  296. extern const char* ped_partition_get_name (const PedPartition* part);
  297. extern int ped_partition_is_busy (const PedPartition* part);
  298. extern char* ped_partition_get_path (const PedPartition* part);
  299.  
  300. extern const char* ped_partition_type_get_name (PedPartitionType part_type);
  301. extern const char* ped_partition_flag_get_name (PedPartitionFlag flag);
  302. extern PedPartitionFlag ped_partition_flag_get_by_name (const char* name);
  303. extern PedPartitionFlag ped_partition_flag_next (PedPartitionFlag flag);
  304.  
  305. /** @} */
  306.  
  307. /**
  308.  * \addtogroup PedDisk
  309.  * @{
  310.  */
  311.  
  312. extern int ped_disk_add_partition (PedDisk* disk, PedPartition* part,
  313.                                    const PedConstraint* constraint);
  314. extern int ped_disk_remove_partition (PedDisk* disk, PedPartition* part);
  315. extern int ped_disk_delete_partition (PedDisk* disk, PedPartition* part);
  316. extern int ped_disk_delete_all (PedDisk* disk);
  317. extern int ped_disk_set_partition_geom (PedDisk* disk, PedPartition* part,
  318.                                         const PedConstraint* constraint,
  319.                                         PedSector start, PedSector end);
  320. extern int ped_disk_maximize_partition (PedDisk* disk, PedPartition* part,
  321.                                         const PedConstraint* constraint);
  322. extern PedGeometry* ped_disk_get_max_partition_geometry (PedDisk* disk,
  323.                 PedPartition* part, const PedConstraint* constraint);
  324. extern int ped_disk_minimize_extended_partition (PedDisk* disk);
  325.  
  326. extern PedPartition* ped_disk_next_partition (const PedDisk* disk,
  327.                                               const PedPartition* part);
  328. extern PedPartition* ped_disk_get_partition (const PedDisk* disk, int num);
  329. extern PedPartition* ped_disk_get_partition_by_sector (const PedDisk* disk,
  330.                                                        PedSector sect);
  331. extern PedPartition* ped_disk_extended_partition (const PedDisk* disk);
  332.  
  333. /* internal functions */
  334. extern PedDisk* _ped_disk_alloc (const PedDevice* dev, const PedDiskType* type);
  335. extern void _ped_disk_free (PedDisk* disk);
  336.  
  337.  
  338. /** @} */
  339.  
  340. /**
  341.  * \addtogroup PedPartition
  342.  *
  343.  * @{
  344.  */
  345.  
  346. extern PedPartition* _ped_partition_alloc (const PedDisk* disk,
  347.                                            PedPartitionType type,
  348.                                            const PedFileSystemType* fs_type,
  349.                                            PedSector start,
  350.                                            PedSector end);
  351. extern void _ped_partition_free (PedPartition* part);
  352.  
  353. extern int _ped_partition_attempt_align (
  354.                 PedPartition* part, const PedConstraint* external,
  355.                 PedConstraint* internal);
  356.  
  357. #endif /* PED_DISK_H_INCLUDED */
  358.  
  359. /** @} */
  360.  
  361.